/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

/**
 *
 * @author Maxym
 */
public class Word {

    private static final int EOF_CODE = 100;
    public static final Word EOF = new Word("$", EOF_CODE, 0, 0);
    public static final int COMMENT = 7;
    public static final int IDENTIFIER = 0;
    private String wordString;
    private int wordClass;
    private String wordClassName;
    private int wordCode;
    private int rowNumber;

    public Word(String wordString, int wordClass, int wordCode, int rowNumber) {
        this.wordString = wordString;
        this.wordClass = wordClass;
        this.wordCode = wordCode;
        this.rowNumber = rowNumber;

        switch (wordClass) {
            case 0:
                wordClassName = "Ідентифікатор користувача";
                break; //IDENTIFIER CONST
            case 1:
                wordClassName = "Ключове слово";
                break;
            case 2:
                wordClassName = "Ціле число";
                break;
            case 3:
                wordClassName = "Дійсне число";
                break;
            case 4:
                wordClassName = "Символи операцій";
                break;
            case 5:
                wordClassName = "Символи розділення";
                break;
            case 6:
                wordClassName = "Текст";
                break;
            case 7:
                wordClassName = "Коментар";
                break; //COMMENT CONST
            default:
                wordClassName = "???";
        }
    }

    /**
     * @return повертає сам лексему (тобто як вона виглядить в коді)
     */
    public String getWordName() {
        return wordString;
    }

    public String getWordClassName() {
        return wordClassName;
    }

    public int getWordCode() {
        return wordCode;
    }

    public int getWordClass() {
        return wordClass;
    }

    public int getRowNumber() {
        return rowNumber;
    }

    /**
     * @return символний код лексеми
     * (наприклад: identifier, k03, s02 і т.д).
     */
    public String getSymbolic() {
        // String forReturn = "";

        switch (wordClass) {
            case 0:
                return "identifier";
            case 1:
                return "k" + ((wordCode > 9) ? Integer.toString(wordCode) : "0" + Integer.toString(wordCode));
            case 2:
                return "integer";
            case 3:
                return "float";
            case 4:
                return "o" + ((wordCode > 9) ? Integer.toString(wordCode) : "0" + Integer.toString(wordCode));
            case 5:
                return "s" + ((wordCode > 9) ? Integer.toString(wordCode) : "0" + Integer.toString(wordCode));
            case 6:
                return "text";
            //case 7: wordClassName = "Коментар"; break;
            case EOF_CODE:
                return "$"; // ----
            default:
                return "???";
        }
    }
}
